package main

import "fmt"

type Num struct {
	x, y, v int
}

func (n *Num) Sub(num *Num) bool {
	return num.x >= n.x && num.y >= n.y && num != n
}

type Node struct {
	num  *Num
	subs []*Num
}

var nodes = make([]*Node, 0, 81)
var dt [9][9]*Num

func main() {
	var n int
	fmt.Scanln(&n)
	for true {
		var x, y, v int
		fmt.Scanf("%d %d %d\n", &x, &y, &v)
		if x == y && x == v && x == 0 {
			break
		}
		num := &Num{
			x: x - 1,
			y: y - 1,
			v: v,
		}
		if v > 0 {
			for _, node := range nodes {
				if node.num.Sub(num) {
					node.subs = append(node.subs, num)
				}
			}
			nodes = append(nodes, &Node{
				num:  num,
				subs: make([]*Num, 0, (9-num.x)*(9-num.y)),
			})
		}
		dt[x-1][y-1] = num
	}
	for _, node := range nodes {
		fmt.Printf("Node Pos: %#v\n", *node.num)
		for _, sub := range node.subs {
			fmt.Printf("Node Subs: %#v\n", *sub)
		}
		fmt.Println()
	}
}
